package com.example.spinning.controller;

import com.example.spinning.bean.EndQuality;
import com.example.spinning.bean.RespBean;
import com.example.spinning.bean.SemiQuality;
import com.example.spinning.service.EndQualityService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/endProduct")
public class EndQualityController {
    @Autowired
    EndQualityService endQualityService;

    //增加记录
    @RequestMapping(value = "/add/", method = RequestMethod.POST)
    public RespBean addNewEndQuality( EndQuality endQuality) {
        int result = endQualityService.addNewEndQuality(endQuality);
        if (result == 1) {
            return new RespBean("success",  "成品信息添加成功");
        } else {
            return new RespBean("error","添加成品信息成功");
        }
    }

    //根据id删除记录
    @RequestMapping(value = "/delete/{ids}", method = RequestMethod.DELETE)
    public RespBean deleteById(@PathVariable Long[] ids) {
        boolean result = endQualityService.deleteEndQualityById(ids);
        if (result) {
            return new RespBean("success", "删除成功!");
        }
        return new RespBean("error", "删除失败!");
    }

    @RequestMapping(value = "/getByMix/", method = RequestMethod.GET)
    public Map<String, Object> findPage(Integer page, Integer size,String batch_no, String name, Date date){
        PageInfo<EndQuality> pageInfor = endQualityService.findPage(page, size,batch_no,name, date);
        Map<String, Object> map = new HashMap<>();
        map.put("totleCount",pageInfor.getTotal());
        map.put("list",pageInfor.getList());
        return map;

    }


    @RequestMapping(value = "/update/",method = RequestMethod.PUT)
    public RespBean updateById(EndQuality endQuality){

        int result = endQualityService.updateCategoryById(endQuality);
        if (result == 1) {
            return new RespBean("success",  "成品信息修改成功");
        } else {
            return new RespBean("error","成品信息修改失败");
        }
    }



}

